﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LibraryO2S;
using System.Data;
using System.Web.UI.HtmlControls;

public partial class Administrator_question : System.Web.UI.Page
{
    private QuestionController objQuestion = new QuestionController();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindData();
        }
    }

    private void bindData()
    {
        try
        {
            CollectionPager1.DataSource = objQuestion.GetAll().DefaultView;
            CollectionPager1.BindToControl = rptData;
            CollectionPager1.PageSize = 20;
            CollectionPager1.DataBind();
            rptData.DataSource = CollectionPager1.DataSourcePaged;
            rptData.DataBind();
        }
        catch
        {
            divMessage.InnerHtml = O2S_Message.Warning("Cảnh Báo", "Chưa Có dữ liệu trong mục này!");
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {

    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        try
        {
            string del_list = hdfCheck.Value;
            string[] sp_list = del_list.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < sp_list.Length; i++)
            {
                objQuestion.Delete(sp_list[i]);
            }
            bindData();
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Cảnh Báo", "Phát hiện lỗi! " + ex.Message);
        }
    }

    protected void btnDelete2_Click(object sender, EventArgs e)
    {
        btnDelete_Click(sender, e);
    }
    protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
    {
        string type = ddlType.SelectedValue;
        if (type != "-1")
        {
            try
            {
                CollectionPager1.DataSource = objQuestion.GetByType(type).DefaultView;
                CollectionPager1.BindToControl = rptData;
                CollectionPager1.PageSize = 20;
                CollectionPager1.DataBind();
                rptData.DataSource = CollectionPager1.DataSourcePaged;
                rptData.DataBind();
            }
            catch
            {
                divMessage.InnerHtml = O2S_Message.Warning("Cảnh Báo", "Không có dữ liệu!");
            }
        }
        else
        {
            bindData();
        }

    }
    protected void rptData_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        DataRowView dr = (DataRowView)e.Item.DataItem;
        string id = dr["ID"].ToString();
        if (id == "47" || id == "24" || id == "20" || id == "27")
        {
            HtmlAnchor edit = (HtmlAnchor)e.Item.FindControl("edit2");
            HtmlGenericControl edit2 = (HtmlGenericControl)e.Item.FindControl("edit");
            HtmlGenericControl delete = (HtmlGenericControl)e.Item.FindControl("delete");
            edit.HRef = "#";
            edit.Attributes.Add("style", "font-Weight:bold");
            edit2.InnerHtml = "*";
            delete.InnerHtml = "*";
        }
    }
}